<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="/layui/css/layui.css">
<script type="text/javascript" src="/layui/layui.js"></script>
<title>Insert title here</title>
</head>
<body>

		<div id="div_id1" style="display:none">
		<form id="form_id1" class="layui-form" action="" onclick="return false">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">跟踪时间</label>
					<div class="layui-input-inline">
						<input type="text" id="FollowTime" name="FollowTime"
							lay-verify="required" lay-verify="title" autocomplete="off"
							placeholder="请输入" class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">跟踪状态</label>
					<div class="layui-input-inline">
						<select id="FollowState" name="FollowState" class="layui-input"
							lay-verify="required" lay-filter="aihao">
							<option value=""></option>
							<option value="思量">思量</option>
							<option value="上门未报名">上门未报名</option>
							<option value="报名未进班">报名未进班</option>
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">跟踪类型</label>
					<div class="layui-input-inline">
						<input type="text" id="FollowType" name="FollowType"
							lay-verify="required" lay-verify="title" autocomplete="off"
							placeholder="请输入" class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">下次跟踪时间</label>
					<div class="layui-input-inline">
						<input type="text" id="NextFollowTime" name="NextFollowTime" lay-verify="required"
							lay-verify="title" autocomplete="off" placeholder="请输入"
							class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">备注</label>
					<div class="layui-input-inline">
						<input type="text" id="Content" name="Content" lay-verify="required"
							placeholder="" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					<div class="layui-input-block">
						<button type="submit" class="layui-btn" lay-submit=""
							lay-filter="genzong">跟踪</button>

					</div>
				</div>
			</div>
		</form>
	</div>

					<div style="display:none" id="addDy">
		<form class="layui-form" action="" id="fromDy" lay-filter="fromff">
			<div style="display: none"  class="layui-form-item">
				<label class="layui-form-label">学员名</label>
				<div class="layui-input-block">
					<input type="text" name="StudentName"  id="StudentName" lay-verify="required"
						lay-reqtext="" placeholder="请输入学员姓名" autocomplete="off"
						class="layui-input">
				</div>
			</div>
	<div  style="display: none"  class="layui-form-item">
				<label class="layui-form-label">学生Id</label>
				<div class="layui-input-block">
					<input type="text" name="StudentId" id="StudentId" lay-verify="required"
						 placeholder="请输入学生Id" autocomplete="off"
						class="layui-input">
				</div>
			</div>
	<div class="layui-form-item">
				<label class="layui-form-label">消息内容</label>
				<div class="layui-input-block">
					<input type="text" name="MessageContent" id="MessageContent" lay-verify="required"
						 placeholder="请输入消息内容" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			
		<div style="display: none" class="layui-form-item">
				<label class="layui-form-label">是否打开</label>
				<div class="layui-input-block">
					<input value="否" type="text" name="IsOpen" id="IsOpen" lay-verify="required"
						 placeholder="请输入是否打开" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			
			
			<div class="layui-form-item">
				<div class="layui-input-inline">
					<button type="submit" class="layui-btn" lay-submit=""
						lay-filter="addDy">添加</button>
				</div>
			</div>
		</form>
	</div>
			
					
		
			<div id="div_id" style="display:none">
		<form lay-filter="form_id" id="form_id" class="layui-form" action="" onclick="return false">
			<div class="layui-form-item">
				<div class="layui-inline">
					<input name="Id" type="hidden" id="Id"/>
					<label class="layui-form-label">姓名</label>
					<div class="layui-input-inline">
						<input type="text" id="Name1" name="Name"
							lay-verify="title" autocomplete="off" placeholder="请输入"
							class="layui-input">
					</div>
					<label class="layui-form-label">年龄</label>
					<div class="layui-input-inline">
						<input type="text" id="Age1" name="Age"
							lay-verify="title" autocomplete="off" placeholder="请输入"
							class="layui-input">
					</div>
					<label class="layui-form-label">性别</label>
					<div class="layui-input-inline">
						<input type="text" id="Sex1" name="Sex"
							lay-verify="title" autocomplete="off" placeholder="请输入"
							class="layui-input">
					</div>
					<label class="layui-form-label">电话</label>
					<div class="layui-input-inline">
						<input type="text" id="Phone1" name="Phone"
							lay-verify="title" autocomplete="off" placeholder="请输入"
							class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">咨询师</label>
					<div class="layui-input-block">
						<select class="AskerId" name="AskerId1" id="AskerId1" lay-filter="aihao">
							<option value=""></option>							

						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">是否缴费</label>
					<div class="layui-input-block">
						<select id="IsPay1" lay-filter="aihao">
							<option value=""></option>
							<option value="是">是</option>
							<option value="否">否</option>

						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">是否有效</label>
					<div class="layui-input-block">
						<select id="IsValid1" lay-filter="aihao">
							<option value=""></option>
							<option value="待定">待定</option>
							<option value="是">是</option>
							<option value="否">否</option>

						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">是否回访</label>
					<div class="layui-input-inline">
						<select id="IsReturnVist1" lay-filter="aihao">
							<option value=""></option>
							<option value="是">是</option>
							<option value="否">否</option>
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">QQ</label>
					<div class="layui-input-block">
						<input type="text" id="QQ1" name="QQ"
							lay-verify="title" autocomplete="off" placeholder="请输入"
							class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					<div class="layui-input-block">
						<button type="submit" class="layui-btn" lay-submit=""
							lay-filter="xiugai">修改</button>
					</div>
				</div>
			</div>

		</form>
	</div>
			
			<div style="display:none" id="addStudents">
		<form class="layui-form" action="" id="fromstudent" lay-filter="fromf">
			<div class="layui-form-item">
				<label class="layui-form-label">学员名</label>
				<div class="layui-input-block">
					<input type="text" name="Name"  id="Name" lay-verify="required"
						lay-reqtext="" placeholder="请输入学员姓名" autocomplete="off"
						class="layui-input">
				</div>
			</div>
	<div class="layui-form-item">
				<label class="layui-form-label">年龄</label>
				<div class="layui-input-block">
					<input type="text" name="Age" id="Age" lay-verify="required"
						 placeholder="请输入年龄" autocomplete="off"
						class="layui-input">
				</div>
			</div>
	<div class="layui-form-item">
				<label class="layui-form-label">手机号</label>
				<div class="layui-input-block">
					<input type="text" name="Phone" id="Phone" lay-verify="required|phone"
						 placeholder="请输入手机号" autocomplete="off"
						class="layui-input">
				</div>
			</div>
	<div class="layui-form-item">
				<label class="layui-form-label">性别</label>
				<div class="layui-input-block">
					<input type="text" name="Sex" id="Sex" lay-verify="required"
						 placeholder="请输入性别" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">来源渠道</label>
				<div class="layui-input-block">
					<input type="text" name="MsgSource" id="MsgSource" lay-verify="required"
						 placeholder="请输入来源渠道" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">来源网站</label>
				<div class="layui-input-block">
					<input type="text" name="SourceUrl" id="SourceUrl" lay-verify="required"
						 placeholder="请输入来源网站" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">来源关键词</label>
				<div class="layui-input-block">
					<input type="text" name="SourceKeyWord" id="SourceKeyWord" lay-verify="required"
						 placeholder="请输入来源来源关键词" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-inline">
					<button type="submit" class="layui-btn" lay-submit=""
						lay-filter="addStu">添加</button>
				</div>
			</div>
		</form>
	</div>


	<div>
		<form class="layui-form" action="">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">姓名</label>
					<div class="layui-input-inline">
						<input type="text" id="Name" name="Name"
							lay-verify="title" autocomplete="off" placeholder="请输入"
							class="layui-input">
					</div>
					<label class="layui-form-label">电话</label>
					<div class="layui-input-inline">
						<input type="text" id="Phone" name="Phone"
							lay-verify="title" autocomplete="off" placeholder="请输入"
							class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">咨询师</label>
					<div class="layui-input-block">
						<select class="AskerId" id="AskerId" lay-filter="aihao">
							<option value=""></option>
							

						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">是否缴费</label>
					<div class="layui-input-block">
						<select id="IsPay" lay-filter="aihao">
							<option value=""></option>
							<option value="是">是</option>
							<option value="否">否</option>

						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">是否有效</label>
					<div class="layui-input-block">
						<select id="IsValid" lay-filter="aihao">
							<option value=""></option>
							<option value="待定">待定</option>
							<option value="是">是</option>
							<option value="否">否</option>

						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">是否回访</label>
					<div class="layui-input-inline">
						<select id="IsReturnVist" lay-filter="aihao">
							<option value=""></option>
							<option value="是">是</option>
							<option value="否">否</option>
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">QQ</label>
					<div class="layui-input-block">
						<input type="text" id="QQ" name="QQ"
							lay-verify="title" autocomplete="off" placeholder="请输入"
							class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">创建时间</label>
					<div class="layui-input-inline">
						<input type="text" id="beginCreateTime" name="beginCreateTime"
							placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
					</div>
					<div class="layui-form-mid">-</div>
					<div class="layui-input-inline">
						<input type="text" id="endCreateTime" name="endCreateTime"
							placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">上门时间</label>
					<div class="layui-input-inline">
						<input type="text" id="beginHomeTime" name="beginHomeTime"
							placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
					</div>
					<div class="layui-form-mid">-</div>
					<div class="layui-input-inline">
						<input type="text" id="endHomeTime" name="endHomeTime"
							placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					<div class="layui-input-block">
						<button type="submit" class="layui-btn" lay-submit=""
							lay-filter="cha">检索</button>

					</div>
				</div>
			</div>

		</form>
	</div>

	<div class="layui-inline">
			
				<button type="submit" class="layui-btn" lay-submit=""
			lay-filter="add">添加</button>
			</div>

	<table id="demo" lay-filter="test"></table>
 

 <script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="add">跟踪</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	<a class="layui-btn layui-btn-xs" lay-event="tj">添加动态</a>
</script>
<script>
	layui.use(['table','form','laydate'], function(){
	  var table = layui.table;
	  var form=layui.form;
	  var laydate=layui.laydate;
	  var $=layui.$;
	    laydate.render({
   			 elem: '#beginCreateTime' //指定元素
  		});
  		laydate.render({
   			 elem: '#endCreateTime' //指定元素
  		});
  		laydate.render({
   			 elem: '#beginHomeTime' //指定元素
  		});
  		laydate.render({
   			 elem: '#endHomeTime' //指定元素
  		});
  		laydate.render({
   			 elem: '#FollowTime' //指定元素
   			  ,type: 'datetime'
  		});
  		laydate.render({
   			 elem: '#NextFollowTime' //指定元素
   			  ,type: 'datetime'
  		});
	  //第一个实例
	  table.render({
	    elem: '#demo'
	    ,id:'table_stu_id'
	    ,url: '/students/getStuByWhere' //数据接口
	    ,page: true //开启分页
	    ,cols: [[ //表头
	      {field: 'Id', title: 'ID', sort: true, fixed: 'left'}
	      ,{field: 'Name', title: '姓名',width:80}
	      ,{field: 'Age', title: '年龄',width:80}
	      ,{field: 'Sex', title: '性别'} 
	      ,{field: 'Phone', title: '手机号'}
	      ,{field: 'StuStatus', title: '学历'}
	      ,{field: 'QQ', title: 'QQ'}
	      ,{field: 'WeiXin', title: '微信'}
	      ,{field: 'CreateTime', title: '创建时间'}
	      ,{field: 'HomeTime', title: '上门时间'}	     
	      ,{field: 'askers', title: '咨询师', sort: true,templet:function(obj){
	      return obj.askers.AskerName
	      }}
	      ,{fixed: 'right', width:200, align:'center', toolbar: '#barDemo'} 
	    ]]
	  });
	  //askers 下拉框
	  	  $.post("/askers/getAskAll",{},function(res){
			for(var i=0;i<res.length;i++){
				 $(".AskerId").append(`<option value="${res[i].askerId}">${res[i].askerName}</option>`);
			}
				form.render('select'); //刷新select选择框渲染
			},"json");
	  //检索
	  form.on('submit(cha)',function(){	  	
	  	table.reload('table_stu_id',{
			  	where:{
			  		Name:$("#Name").val(),
			  		Phone:$("#Phone").val(),
			  		AskerId:$("#AskerId").val(),
			  		IsPay:$("#IsPay").val(),
			  		IsValid:$("#IsValid").val(),
			  		IsReturnVist:$("#IsReturnVist").val(),
			  		QQ:$("#QQ").val(),
			  		beginCreateTime:$("#beginCreateTime").val(),
			  		endCreateTime:$("#endCreateTime").val(),
			  		beginHomeTime:$("#beginHomeTime").val(),
			  		endHomeTime:$("#endHomeTime").val()
			  	}
	 		 })
	  		 
	 	 return false;
	  })
	   
	  
	  form.on("submit(add)",function(data){
			layer.open({
			type:1,
			content:$("#addStudents"),
			area:['600px','600px']
		})
			return false;
	})
  		form.on("submit(addStu)",function(data){
			$.post("/students/insertStudent",$("#fromstudent").serialize(),function(res){
				if (res.code=="0") {
				layer.closeAll();
				layer.msg(res.msg,{icon:1,time:100},function(){
				setTimeout('window.location.reload()',100);
				});
		  		
					
				} else{
					layer.msg(res.msg);
				}
				
			},"json")
			return false;
		})
	  
	  
	  
	  
	  
	  form.on("submit(addDy)",function(data){
			$.post("/dynami/insertDynamicmessages",$("#fromDy").serialize(),function(res){
				if (res.code=="0") {
				layer.closeAll();
				layer.msg(res.msg,{icon:1,time:100},function(){
				setTimeout('window.location.reload()',100);
				});
		  		
					
				} else{
					layer.msg(res.msg);
				}
				
			},"json")
			return false;
		})
	  
	  

	   //工具条事件
		table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
		  var data = obj.data; //获得当前行数据
		  var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
		  var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
		 if(layEvent === 'add'){ //跟踪
    			//do somehing
    			console.log(obj.data)
    			layer.open({
					type:1,
					content:$("#div_id1"),   
					area:["400px","400px"] 			
    			})
    			form.on('submit(genzong)',function(){
			$.post("/Net/addNet",{
				UserId:obj.data.AskerId,
				StudentName:obj.data.Name,
				StudentId:obj.data.Id,
				FollowTime:$("#FollowTime").val(),
				NextFollowTime:$("#NextFollowTime").val(),
				Content:$("#Content").val(),
				FollowType:$("#FollowType").val(),
				FollowState:$("#FollowState").val()
			},function(res){
				if(res.code=="0"){
					layer.closeAll();
					layer.msg(res.msg);
				}else{
					layer.msg(res.msg);
				}
			},"json")
			return false;
		})
  		} 
		  if(layEvent === 'del'){ //删除
		    layer.confirm('真的删除行么', function(index){
		      obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
		      layer.close(index);
		      //向服务端发送删除指令
		      console.log(obj.data.Id)
		      $.post("/students/delStu",{
		      	id:obj.data.Id
		      },function(res){
		      	if(res.code=="0"){
		      		layer.closeAll();
		      		layer.msg(res.msg);
		      	}else{
		      		layer.msg(res.msg);
		      	}
		      },"json")
		    });
		  } else if(layEvent === 'edit'){ //编辑
		  form.val("form_id",data);
		    //do something
		    layer.open({
		    	type:1,
		    	content:$("#div_id"),
		    	area:["400px","500px"]
		    })
		    //同步更新缓存对应的值
		    obj.update({
		      username: '123'
		      ,title: 'xxx'
		    });
		  } else if(layEvent === 'tj'){ //添加
				form.val("fromff",{
					StudentId:data.Id
					,StudentName:data.Name
					})
		       layer.open({
		       type:1,
		       content:$("#addDy"),
					area:['600px','600px']
		       })
		   				 
  					} else if(layEvent === 'LAYTABLE_TIPS'){
		    layer.alert('Hi，头部工具栏扩展的右侧图标。');
		  }
		});
	  	form.on('submit(xiugai)',function(){
	  		$.post("/students/updaStu",{
	  				Id:$("#Id").val(),
	  				Name:$("#Name1").val(),
	  				Age:$("#Age1").val(),
	  				Sex:$("#Sex1").val(),
			  		Phone:$("#Phone1").val(),
			  		AskerId:$("#AskerId1").val(),
			  		IsPay:$("#IsPay1").val(),
			  		IsValid:$("#IsValid1").val(),
			  		IsReturnVist:$("#IsReturnVist1").val(),
			  		QQ:$("#QQ1").val()
			  		
	  		},function(res){
	  			if(res.code=="0"){
	  				layer.closeAll();
	  				table.reload("table_stu_id");
	  				layer.msg(res.msg);
	  			}else{
	  				layer.msg(res.msg);
	  			}
	  		},"json")
	  		return false;
	  	})

	});
</script>
</body>
</html>